function bestCharge(selectedItems) {
  
  let selectArray = bestCharge();
  let spliceID = [];
  let spliceNum = [];
  let split = [];
  for(let s of selectArray){
  spliceID.push(s.slice(0,8));
  spliceNum.push(s.slice(11));
  split.push(s.split(" x "));
  }

  let typeArray = loadAllItems();
  let price = [];
  let coutName = [];
  for(let item of spliceID){
    for(let obj of typeArray){
      if(item == obj.id){
        coutName.push(obj.name);
        price.push(obj.price);
      }
    }
  }

  
  let discount = loadPromotions();
  let money = 0;
  let count = 0;
  let sum = 0;
  let typeArr = typeArray; 
  let arr = discount[1].items;
  for(let item of typeArr){
      for(let obj of arr){
          if(item.id == obj){
            item.price = item.price/2;
            break;
          }
      }
      for(let value of split){
          if(item.id==value[0]){
              count = count + item.price*value[1];
          }
      }
  }

  for(let item of typeArray){
    for(let obj of split){
      if(item.id==obj[0]){
        money = money + item.price*obj[1];
      }
    }
  }

 let pro = money - count;
 if(money>=30){
    sum = money - 6;
 }
  
console.log(`============= 订餐明细 =============`)
for(let i = 0;i<spliceID.length;i++){
  console.log(`${coutName[i]} x ${spliceNum[i]} = ${spliceNum[i]*price[i]}元;`)
}
console.log(`===================================`)  
if(spliceID.indexOf('ITEM0001')==-1&&spliceID.indexOf('ITEM0022')==-1){
  console.log(`总计：${money}元\n
===================================`)
}
else if(count < sum)
  {
    console.log(`使用优惠:\n
指定菜品半价(黄焖鸡，凉皮)，省${pro}元\n
-----------------------------------\n
总计：${count}元\n
===================================`)
  }
else
  {
    console.log(`使用优惠:\n
满30减6元，省6元\n
-----------------------------------\n
总计：${sum}元\n
===================================`)
  }
};
